#include "checkupdate.h"


#include <QDebug>


CheckUpdate::CheckUpdate(QObject *parent) : QObject(parent)
{
}

void CheckUpdate::Check(QString currver)
{
    CurrVer=currver;
    m_network = new QNetworkAccessManager(); //可运行但此处报错：QObject::connect: Cannot connect (null)::aboutToQuit() to QNativeWifiEngine::closeHandle()，暂无解决方案
    QObject::connect(m_network, SIGNAL(finished(QNetworkReply*)),this ,SLOT(replyFinished(QNetworkReply*)));
    QString url="http://update.moolink.cn/mx/updata/ver.txt";
    m_network->get(QNetworkRequest(QUrl(url)));
}

void CheckUpdate::replyFinished(QNetworkReply *reply)
{
    const QString onlineVer=reply->readAll().data();
    if(onlineVer.size()>0&&onlineVer.size()<10)
    {
        if(onlineVer.size()!=CurrVer.size()||!CurrVer.startsWith(onlineVer))
        {
            emit needUpdate(onlineVer);
        }
    }
}
